<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教师后台-不学也通-学生修改</title>
    <link rel="shortcut icon" href="../康笑长结业课.jpg" type="image/x-icon">
    <style>
        .container {
            min-height: 100vh;
        }

        .container .nav {
            height: 100%;
            background-color: #fff;
        }

        .link-secondary{
            text-decoration: none;
        }
        .link-secondary:hover{
            color: #0d6efd !important;
            
        }
    </style>
</head>
<body>
    <!-- container是bootstrap的居中窄的显示方案 -->
    <div class="container bg-body">
        <div class="row">
            <div class="col-md-2 leftmenu" id="leftmenu"></div>
            <div class="col-md-9 col-xs-12 kc ms-3">
                <div class="row mt-3 pd-3 border-bottom border-secondary">
                    <div class="col-md-2">编辑学生</div>
            </div>
            <div class="row mt-3">
            <form class="col-md-5" id="studentForm">
                <div class="mb-3">
                  <label for="tel" class="form-label">手机:</label>
                  <input name="tel" type="tel" required class="form-control" id="tel" 
                  aria-describedby="tel" placeholder="请输入手机号">
                </div>
                <div class="mb-3">
                    <label  for="sno" class="form-label">学号:</label>
                    <input name="sno" type="number" required class="form-control" id="sno" 
                    aria-describedby="tel" placeholder="请输入学号">
                </div>
                <div class="mb-3">
                  <label  for="name" class="form-label">姓名:</label>
                  <input name="name" type="text" required class="form-control" id="name" 
                  aria-describedby="tel" placeholder="请输入姓名">
                </div>
                <div class="mb-3">
                    <button type="button" class="btn btn-success">保存</button>
                </div>
              </form>
            </div>
       </div>
   </div>
</div>
    <script type="module" src="../js/main.js"></script>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/common.js"></script>
    <script>
         function getUrlParams(key) {// 获取网址中参数信息"key"中放属性名
            var url = window.location.search.substr(1);
            if (url == '') {
                return false;
            }
            var paramsArr = url.split('&');
            for (var i = 0; i < paramsArr.length; i++) {
                var combina = paramsArr[i].split("=");
                if (combina[0] == key) {
                    return combina[1];
                }
            }
            return false;
        }
        // console.log(getUrlParams("id"));
        // 获取将要编辑的数据信息
        // 遇到问题 不知道怎么获取页面网址上的id值
        $.get(`http://unicloud.codecore.cn/ms/getStudent?id=${getUrlParams("id")}`,{},function(params){
            if(params.errCode == 0){
                $("#tel").val(params.data.tel);
                $("#name").val(params.data.student_name)
                $("#sno").val(params.data.sno);
            }
        })
        // 点击保存更新数据
        $(".btn-success").click(function(){
            $.post("http://unicloud.codecore.cn/ms/studentUpdate",{
                id:getUrlParams("id"),
                tel:$("#tel").val(),
                student_name:$("#name").val(),
                sno:$("sno").val(),
            },function(params){
                if(params.errCode==0){// 更新成功跳转回去
                    histopy.back()
                }else{
                    alert("更新失败")
                }
            })
        })
    </script>
</body>
</html>